package gui.houseeditor;

import gui.houseeditor.strategies.MinimalisticHouseDrawStrategy.WalkerImage;

import java.util.LinkedList;
import java.util.List;


public abstract class AbstractHouseModel implements HouseModel {

	protected List<HouseDataListener> listeners = new LinkedList<HouseDataListener>();
	protected int width, height;

	public AbstractHouseModel(int w, int h) {
		width = w;
		height = h;
	}

	public void addHouseDataListener(HouseDataListener l) {
		listeners.add(l);
	}

	public HouseDataListener[] getMazeDataListeners() {
		return (HouseDataListener[]) listeners.toArray();
	}

	public void removeHouseDataListener(HouseDataListener l) {
		listeners.remove(l);
	}

	protected void fireValueChanged(Object source, int x, int y, WalkerImage s) {
		final HouseDataEvent e = new HouseDataEvent(source, x, y, s);
		for (HouseDataListener l : listeners)
			l.valueChanged(e);

	}

	protected void fireValueChanged(Object source, Stanza s) {
		final HouseDataEvent e = new HouseDataEvent(source, 0, 0, null);
		for (HouseDataListener l : listeners)
			l.valueChanged(e);

	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public abstract HouseObject getCell(int x, int y);

	public abstract void setCell(HouseObject o, int x, int y);


}
